package com.fk.adapter;

import java.util.List;

import com.fk.adapter.QuestItemAdapter.ViewHolder;
import com.fk.bean.Food;
import com.fk.regimen.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FoodDetailAdapter extends BaseAdapter {

	//接收到的数据集合
	List<Food> list;
	//上下文参数：表示哪个界面想调用此适配器
	Context context;
	//LayoutInflater：专门用来初始化视图
	LayoutInflater mInflater;
		
		
	String tag = "china";
		
	public FoodDetailAdapter(List<Food> list, Context context){
		super();
		this.list = list;
		this.context = context;
		mInflater = LayoutInflater.from(context);
	}
	
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder;
		
		
		//1、指定每一行的布局；2、指定每一行布局绑定的数据
		//convertView：表示每一行返回的布局
		//加载第一行数据时，convertView为空，从第二行开始，都使用第一行指定的布局
		if(convertView == null){
			convertView = mInflater.inflate(R.layout.introfood_listitem, null);
			viewHolder = new ViewHolder();
			
			//指定每一行布局的具体图片或文本
			viewHolder.img_introfruit = (ImageView) convertView.findViewById(R.id.img_introfruit);
			viewHolder.tv_introfruitname = (TextView) convertView.findViewById(R.id.tv_introfruitname);
			viewHolder.tv_suitphy = (TextView) convertView.findViewById(R.id.tv_suitphy);
			viewHolder.img_tofooddetail = (ImageView) convertView.findViewById(R.id.img_tofooddetail);
			
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
//		viewHolder.tv_questdescrib.setText(list.get(position).getQdescription());
		viewHolder.img_introfruit.setImageResource(list.get(position).getFimagepath());
		viewHolder.tv_introfruitname.setText(list.get(position).getFname());
		viewHolder.tv_suitphy.setText("平和质喽");
		viewHolder.img_tofooddetail.setImageResource(R.drawable.youjiantou);
		
		
		return convertView;
	}
	
	
	class ViewHolder{
		ImageView img_introfruit;
		TextView tv_introfruitname;
		TextView tv_suitphy;
		ImageView img_tofooddetail;
	}

}
